package cn.iocoder.yudao.module.erp.dal.mysql.purchaseplan.purchasematerialdetail;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.purchaseplan.vo.purchasematerialdetail.PurchaseMaterialDetailPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchaseplan.purchasematerialdetail.PurchaseMaterialDetailDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 物料采购计划明细 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PurchaseMaterialDetailMapper extends BaseMapperX<PurchaseMaterialDetailDO> {

    default PageResult<PurchaseMaterialDetailDO> selectPage(PurchaseMaterialDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PurchaseMaterialDetailDO>()
                .eqIfPresent(PurchaseMaterialDetailDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(PurchaseMaterialDetailDO::getPurchaseType, reqVO.getPurchaseType())
                .eqIfPresent(PurchaseMaterialDetailDO::getMaterialCode, reqVO.getMaterialCode())
                .likeIfPresent(PurchaseMaterialDetailDO::getMaterialName, reqVO.getMaterialName())
                .eqIfPresent(PurchaseMaterialDetailDO::getUnit, reqVO.getUnit())
                .eqIfPresent(PurchaseMaterialDetailDO::getSpecification, reqVO.getSpecification())
                .eqIfPresent(PurchaseMaterialDetailDO::getAcceptanceStandard, reqVO.getAcceptanceStandard())
                .eqIfPresent(PurchaseMaterialDetailDO::getBrandRequirements, reqVO.getBrandRequirements())
                .eqIfPresent(PurchaseMaterialDetailDO::getPackagingRequirements, reqVO.getPackagingRequirements())
                .eqIfPresent(PurchaseMaterialDetailDO::getEstimatedQuantity, reqVO.getEstimatedQuantity())
                .eqIfPresent(PurchaseMaterialDetailDO::getEstimatedUnitPrice, reqVO.getEstimatedUnitPrice())
                .eqIfPresent(PurchaseMaterialDetailDO::getTotalAmount, reqVO.getTotalAmount())
                .eqIfPresent(PurchaseMaterialDetailDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(PurchaseMaterialDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PurchaseMaterialDetailDO::getId));
    }

    default void deleteByPlanId(Long planId){
        LambdaUpdateWrapper<PurchaseMaterialDetailDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(PurchaseMaterialDetailDO::getPlanId, planId);
        this.delete(updateWrapper);
    }

    default List<PurchaseMaterialDetailDO> selectByPlanId(Long planId){
        LambdaQueryWrapper<PurchaseMaterialDetailDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PurchaseMaterialDetailDO::getPlanId, planId)
                .eq(PurchaseMaterialDetailDO::getDeleted,0);
        return this.selectList(queryWrapper);
    }
}